#pragma once
#include <stdint.h>

template<typename TYPE>
class Buffer
{
public:
	Buffer();
	~Buffer();

	bool  Init(TYPE* alloc, uint32_t init_size);
	void  Release();
	char* GetWritePtr();
	char* GetReadPtr();

	uint32_t GetSize();
	uint32_t GetReadLength();
	uint32_t GetWriteSpace();

	bool Resize();
	bool Read(uint32_t len);
	int  Write(uint32_t len, bool decrypt = true);
	int  Write(const char* buf, uint32_t len, bool encrypt = true);

protected:
	bool ReallocBuffer(uint32_t len);

protected:
	char*     buf_;
	uint32_t  size_;
	uint32_t  offset_;
	uint32_t  init_size_;
	TYPE*     alloc_;
};

#include "buffer.hpp"
